﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Easy.Domain.Core;
using Easy.Domain.Test.Models;
using System.Configuration;
using Easy.Domain.Test.Service;
using Easy.Domain.Test.Repository;
using Easy.Common;
using System.Reflection;
using Easy.ServiceLocator.Unity;
using Easy.ServiceLocator;
using Easy.Common.RegisterType;
using Easy.ServiceLocator.Unity.Interceptor;
using Easy.Plugin;

namespace Easy.Domain.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var resss = RegisterTypeAnalyser.Analyze(Assembly.GetExecutingAssembly());
            
            EasyUnity.AutoRegisterType(resss);

            EasyServiceLocator.SetServiceLocator(EasyUnity.GetSingletonContainer());

            var testService1 = EasyServiceLocator.GetInstance<ITestService>();
            var testService2 = EasyServiceLocator.GetInstance<ITestService>();
            bool ise = testService1.Equals(testService2);
            int add = testService1.Add(3, 10);

            var mySelf = EasyServiceLocator.GetInstance<MySelf>();
            mySelf.Add(1, 2);


            var blogRepository = EasyServiceLocator.GetInstance<IBlogRepository>();
            var fd = blogRepository.FindById(7);







            string connectionString = ConfigurationManager.ConnectionStrings["EFTestContext"].ToString();

            //SqlQueryProvider<Blog> blogQueryProvider = new SqlQueryProvider<Blog>(connectionString);

            //SqlQueryProvider<VBlog> VBlogQueryProvider = new SqlQueryProvider<VBlog>(connectionString);

            //var Blogs1 = blogQueryProvider.GetPaged(0, 5, "(Url like '%7%' or Url='99') and Id = 7", "Id desc");

            //var Blogs2 = VBlogQueryProvider.GetPaged(0, 5, "(Url like '%7%' or Url='99') and Id = 7", "Id asc");

            //var paramDic = new Dictionary<string, object>();
            //paramDic.Add("@PageIndex", 0);
            //paramDic.Add("PageCount", 5);
            //paramDic.Add("@Url", "77");

            //var Blogs3 = blogQueryProvider.ExecuteProQuery("Pro_GetBlogs", paramDic);

            TestUnitOfWork unitOfWork = new TestUnitOfWork();

            BlogService blogService = new BlogService(new BlogRepository(unitOfWork));




            var blog1 = blogService.FindById(1);
            blog1.Age = 999;



            //blog1.Posts.Add(new Post { neirong = "1", Title = "2" });
            //blog1.Posts.Add(new Post { neirong = "3", Title = "4" });
            //blog1.Posts.Add(new Post { neirong = "5", Title = "6" });

            //Blog blog2 = new Blog { Id = 1, Age = 250, Name = "250", hhh = "hhh" };

            //blog.Posts.First().Title = "bbb";
            //blogService.AddBlog(blog);
            blogService.UpdateBlog(blog1);

            //blogService.UpdateBlogAs1(blog2);
            //blogService.Merge(blog1, blog2);

            Console.Read();
        }
    }
}
